﻿<?php
    /**
      *载入竞赛类
      * 
      *@author kinet 380511703@qq.cn
      *@time 2010-5-10
      *@version 1.1
   */ 
   require_once( 'contest.class.php' ); 
   require_once( 'contest_problem_list.class.php' );     
   class contest_load{
               private $contest_no;
               private $contest;
               private $peoblem_list;//用于存放试题队列
               private $team_list;
               private $tlength;
               private $length;//记录试题队列长度 
               private $db;  
               /**
               * 载入
               * 
               * @param 数据库名
               * @param竞赛名
               */
               public function contest_load($db,$vname){
                   $this->db=$db;
                   $this->contest=new contest($db);
                     $this->contest->load('name',$vname); 
                          $this->contest_no=$this->contest->init_contest_no();                          
                          if($this->contest_no==-1){
                              throw new Exception("竞赛名不存在",7); 
                           }
                            $this->loadcontestproblem();
                            $this->loadcontestteam();
                              
               }
               /**
               * 载入试题
               * 
               */
               private function loadcontestproblem(){                                
                   $this->problem_list=array();
                   $this->length=0;
                   $sql="select * from contest_problem_list where contest_no=".$this->contest_no;                  
                   $res = $this->db->query( $sql ) ;                         
                   if( !$res ){
                        return false ;
                   }
                   while($rows = $res->fetchRow( MDB2_FETCHMODE_ASSOC )){
                       
                       $this->problem_list[$this->length]=$rows['problem_no'];
                       $this->length+=1;                                 
                  } 
                  return true;
                   
               }
               /**
               * 载入队伍
               * 
               */
                private function loadcontestteam(){                                
                   $this->team_list=array();
                   $this->tlength=0;
                   $sql="select * from contest_team where contest_no=".$this->contest_no;                  
                   $res = $this->db->query( $sql ) ;                         
                   if( !$res ){
                        return false ;
                   }
                   while($rows = $res->fetchRow( MDB2_FETCHMODE_ASSOC )){
                       
                       $this->team_list[$this->tlength]=$rows['team_no'];
                       $this->tlength+=1;                                 
                  } 
                  return true;
                   
               }
               
               /**
               * 通过一个数组返回竞赛全部信息
               * 
               */
               public function get_contest(){
                     $result=array();
                     $result['contest_no']=$this->contest_no;
                     $result['name']=$this->contest->get('name');
					 $result['sign_begin_time']=$this->contest->get('sgin_begin_time');
                     $result['sign_end_time']=$this->contest->get('sign_end_time'); 
                     $result['begin_time']=$this->contest->get('begin_time');
                     $result['end_time']=$this->contest->get('end_time'); 
                     $result['summary']=$this->contest->get('summary');  
                     $result['addtime']=$this->contest->get('addtime'); 
					 $result['status']=$this->contest->get('status'); 
                     return $result;
               }
               /**
               * 获取试题返回一个数组
               */
               public function get_problem(){
                   $this->loadcontestproblem();          
                   return $this->problem_list;
                   
               }
                public function get_team(){
                   $this->loadcontestteam();      
                   return $this->team_list;
                   
               }
               public function re_contest_class(){
                   return $this->contest;
               }
   }
?>
       ﻿
